package com.midea.ai.air.ui.more;

import android.app.Activity;
import android.app.Dialog;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.midea.ai.air.R;
import com.midea.ai.air.common.BaseActivity;
import com.midea.ai.air.ui.more.fragment.MoreSettingAirReportDayFragment;
import com.midea.ai.air.ui.more.fragment.MoreSettingAirReportMonthFragment;
import com.midea.ai.air.ui.user.LoginActivity;
import com.midea.ai.air.view.AirReportChartView;
import com.midea.ai.air.view.ShareView;

/**
 * Created by hww on 2016/4/8.
 * 更多-空气报告
 */
public class MoreSettingAirReport extends BaseActivity implements View.OnClickListener {

    private TextView tv_left, tv_day, tv_month;
    private ImageView iv_right;
    private Dialog dialog_share;
    private LinearLayout mLinearLayout;
    private AirReportChartView arView;
    public static final String INDOOR_SELECTED_STRING = "indoor_selected";
    public static String INDOOR_DAY = "day_fragment";
    public static String INDOOR_MONTH = "month_fragment";
    public static String INDOOR_SELECTED_DATE = "selected_fragment";
    public static String INDOOR_TEMP = "indoor_temp";
    public static String INDOOR_HUMIDITY = "indoor_humidity";
    public static String INDOOR_PM = "indoor_pm";
    private MoreSettingAirReportDayFragment fragment_day = new MoreSettingAirReportDayFragment();
    private MoreSettingAirReportMonthFragment fragment_month = new MoreSettingAirReportMonthFragment();
    private FrameLayout layout_content;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_moresettingairreport);

        init();
    }

    private void init() {
        tv_left = (TextView) findViewById(R.id.more_setting_air_report_tv_left);
        tv_day = (TextView) findViewById(R.id.more_setting_air_report_day);
        tv_month = (TextView) findViewById(R.id.more_setting_air_report_month);
        iv_right = (ImageView) findViewById(R.id.more_setting_air_report_iv_right);
        mLinearLayout = (LinearLayout) findViewById(R.id.more_setting_air_report_dm_ll);
        layout_content = (FrameLayout) findViewById(R.id.more_setting_air_report_fragment);

        tv_left.setOnClickListener(this);
        iv_right.setOnClickListener(this);
        tv_day.setOnClickListener(this);
        tv_month.setOnClickListener(this);

        arView = (AirReportChartView) findViewById(R.id.more_setting_air_report_chart_view);

        startFragment(MoreSettingAirReport.this, R.id.more_setting_air_report_fragment, fragment_day);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.more_setting_air_report_tv_left:
                //返回
                finish();
                break;
            case R.id.more_setting_air_report_iv_right:
                //分享
                ShareView shareView = new ShareView(MoreSettingAirReport.this);
                shareView.setShareView(layout_content);
                break;
            case R.id.more_setting_air_report_day:
                //查询日曲线
                select_day();
                break;
            case R.id.more_setting_air_report_month:
                //查询月曲线
                select_month();
                break;

            default:
                break;
        }
    }


    //日曲线按钮
    private void select_day() {
        mLinearLayout.setBackgroundResource(R.drawable.more_setting_air_report_day01);
        tv_day.setTextColor(getResources().getColor(R.color.common_white));
        tv_month.setTextColor(getResources().getColor(R.color.electric_histogram));

        startFragment(MoreSettingAirReport.this, R.id.more_setting_air_report_fragment, fragment_day);
    }

    //月曲线按钮
    private void select_month() {
        mLinearLayout.setBackgroundResource(R.drawable.more_setting_air_report_day02);
        tv_day.setTextColor(getResources().getColor(R.color.electric_histogram));
        tv_month.setTextColor(getResources().getColor(R.color.common_white));

        startFragment(MoreSettingAirReport.this, R.id.more_setting_air_report_fragment, fragment_month);
    }


    public static void startFragment(Activity activity, int R_id_layout, Fragment fragment) {
        activity.getFragmentManager().beginTransaction().replace(R_id_layout, fragment).commit();
    }

}
